capture log close
log using suic-econ-a4-educ.txt, replace text

//  program:    suic-econ-a4-educ.do
//  task:		poisson models by education group
// 	input:		suic-econ-data2-cps.dta
//	output:		suic-econ-atable2-educa3_1 (2) (3).txt
//  project:    economic conditions and suicide
//  author:     sam harper \ 17dec2014

//  #0
//  program setup

version 12
set linesize 80
clear all
macro drop _all
set matsize 11000


// #1 	
// Use restricted data for 1994-2010, limit to ages 25+

* CPS dataset
use suic-econ-data2-cps, clear

* descriptive table
preserve
collapse (sum) suic pop1, by(educ stabb year)
tabstat suic, by(educ) stats(sum)
gen rate = suic / (pop1/12) * 100000
tabstat rate, by(educ) stats(mean sd min max) format(%3.1f)
restore

* drop ages 16-24
drop if agecat==1

* re-scale icei for a 10-unit change
replace icei= -1*icei/10

* run regressions across each education group
qui levelsof educa3, local(levels)
foreach l of local levels {

di "-> Group = `: label (educa3) `l''"



// #2
// crude poisson model without adjustments: Model 0

poisson suic icei if educa3==`l', offset(logpop100y) vce(cluster state) nolog

* predicted marginal effects
eststo educa3_`l'_m_0: estpost margins, dydx(icei) predict(ir) ///
	vce(unconditional) cformat(%4.2f)

* save estimates for plot
qui parmest, saving(educa3_`l'_m_0, replace) 


	
// #3
// now add individual covariates: Model 1

poisson suic icei i.sex i.race2 i.agecat if educa3==`l', offset(logpop100y) ///
	vce(cluster state) nolog irr cformat(%4.3f) 

* predicted marginal effects
eststo educa3_`l'_m_1: estpost margins, dydx(icei sex race2 agecat) predict(ir) ///
	vce(unconditional) cformat(%4.2f)

* save estimates for plot
qui parmest, saving(educa3_`l'_m_1, replace) 
	


// #4
// now add state, season, and year fixed effects: Model 2

poisson suic icei i.sex i.race2 i.agecat i.stabb i.season##i.year ///
	if educa3==`l', offset(logpop100y) vce(cluster state) nolog ///
	irr cformat(%4.3f)

* predicted marginal effects
eststo educa3_`l'_m_2: estpost margins, dydx(icei sex race2 agecat season) ///
	predict(ir) vce(unconditional) cformat(%4.2f) 
	
* save estimates for plot
qui parmest, saving(educa3_`l'_m_2, replace) 



// #5
// now add state-specific linear trends to FE model: Model 3

poisson suic icei i.sex i.race2 i.agecat i.season##i.year ///
	i.stabb##c.quarter if educa3==`l', offset(logpop100y) ///
	vce(cluster state) nolog irr cformat(%4.3f)

* predicted marginal effects
eststo educa3_`l'_m_3: estpost margins, dydx(icei sex race2 agecat season) ///
	predict(ir) vce(unconditional) cformat(%4.2f) 

* save estimates for plot
qui parmest, saving(educa3_`l'_m_3, replace) 	
	

	
// #6
// now add state-specific quadratic time trends to basic FE model: Model 4

poisson suic icei i.sex i.race2 i.agecat i.season##i.year ///
	i.stabb##(c.quarter##c.quarter) if educa3==`l', offset(logpop100y) ///
	vce(cluster state) nolog irr cformat(%4.3f)

* predicted margins
eststo educa3_`l'_m_4: estpost margins, dydx(icei sex race2 agecat season) ///
	predict(ir) vce(unconditional) cformat(%4.2f) 

* save estimates for plot
qui parmest, saving(educa3_`l'_m_4, replace) 	



// #7 	
// include state-specific cubic trends: Model 5

poisson suic icei i.sex i.race2 i.agecat i.season##i.year ///
	i.stabb##(c.quarter##c.quarter##c.quarter) if educa3==`l', ///
	offset(logpop100y) vce(cluster state) nolog irr cformat(%4.3f) 

* predicted margins
eststo educa3_`l'_m_5: estpost margins, dydx(icei sex race2 agecat season) ///
	predict(ir) vce(unconditional) cformat(%4.2f) 

* save estimates for plot
qui parmest, saving(educa3_`l'_m_5, replace) 	



// #8
// write results to file

esttab educa3_`l'_m_* using suic-econ-atable2-educa3_`l'.txt,  ///
	cells("b(fmt(%4.2f)) ci(par( ( , ) ))") collabels(Est. 95%CI) nostar not ///
	nolines nonum mtitle((0) (1) (2) (3) (4) (5)) delimiter(";") replace ///
	
}

	
log close
exit	
